package com.leyou.item.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecGroup;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.service.SpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Response;
import java.util.List;

/**
 * @package com.leyou.item.controller
 * @description:
 * @author: 86157
 * @date 2019/6/26 17:07
 * @version: V1.0
 */
@RestController
@RequestMapping("spec")
public class SpecGroupController {

    @Autowired
    private SpecGroupService specGroupService;

    /**
     * 根据分类id查询规格组信息
     *
     * @param cid
     * @return
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecGroupByCid(@RequestParam("id") Long cid) {
        List<SpecGroupDTO> list = specGroupService.querySpecGroupByCid(cid);

        return ResponseEntity.status(HttpStatus.OK).body(list);
    }

    /**
     * 根据规格组id查询规格参数
     *
     * @param gid
     * @return
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParamByGid(@RequestParam(value = "gid", required = false) Long gid,
                                                                  @RequestParam(value = "cid", required = false) Long cid,
                                                                  @RequestParam(value = "searching", required = false) Boolean searching) {
        return ResponseEntity.ok(specGroupService.querySpecParamByGid(gid, cid, searching));
    }

}